package com.chen.authserver.utils;

import java.util.regex.Pattern;

public class RegexUtils {

    // 验证用户名是否合法，必须是以字母开头，只能包含字母数字下划线和减号，4到16位
//    static final String ACCOUNT_PATTERN = "/^[a-zA-Z]{1}([a-zA-Z0-9]|[._-]){3,15}$/";
//    static final String ACCOUNT_PATTERN = "/^[A-Za-z0-9]{4,15}$/";
    static final String ACCOUNT_PATTERN = "^[a-zA-Z][a-zA-Z0-9]{5,17}$";

    // 验证密码强度，6-16位，,至少有一个数字，一个大写字母，一个小写字母和一个特殊字符，四个任意组合
    static final String PWD_PATTERN = "(?=^.{6,16}$)(?=.*\\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*]).*$";

    static final String EMAIL_PATTERN = "^[a-z0-9]{1}[a-z0-9_-]{1,}@[a-z0-9]{1,}(\\.[a-z]{2,})*\\.[a-z]{2,}$";

    static final String PHONENUMBER_PATTERN = "^1[345678]{1}\\d{9}$";

    static final String IDCARD_PATTERN = "^[1-9]{1}\\d{5}[1-9]{2}\\d{9}[Xx0-9]{1}$";

    public static boolean checkAccount(final String account) {
        return Pattern.matches(ACCOUNT_PATTERN, account);
    }

    public static boolean checkPwd(String pwd) {
        return Pattern.matches(PWD_PATTERN, pwd);
    }

    public static boolean checkEmail(String email) {
        return Pattern.matches(EMAIL_PATTERN, email);
    }

    public static boolean checkPhoneNumber(String phoneNum) {
        return Pattern.matches(PHONENUMBER_PATTERN, phoneNum);
    }

    public static boolean checkIdCard(String idCard) {
        return Pattern.matches(IDCARD_PATTERN, idCard);
    }
}
